#include "CurrentAccount.h"

CurrentAccount::CurrentAccount(int balance, const Date& creationDate)
	: Account(balance), creationDate(creationDate), maxTransactions(INIT_MAX_TRANSACTIONS), transactionIndex(0)
{

}

void CurrentAccount::addTransaction(Transaction& transaction)
{
	//Adding the new transaction
	transactions.push_back(&transaction);

	if (transaction.getTransactionType() == Transaction::eTransactionType::Withdrawal)
	{
		balance -= transaction.getTransferedMoney();
	}
	else if (transaction.getTransactionType() == Transaction::eTransactionType::Deposite)
	{
		balance += transaction.getTransferedMoney();
	}

	//Updating the balance
	
}

void CurrentAccount::toOs(ostream& os) const
{
	
	os << "CurrentAccount={Creation=" << creationDate << " Transactions Count="<< transactionIndex <<"\n\t";
	Account::toOs(os);
	os << "}";
}

CurrentAccount::~CurrentAccount()
{
	Transaction* ptrTransaction = NULL;

	while (!transactions.empty())
	{
		ptrTransaction = transactions.pop_front();

		delete ptrTransaction;
	}
}